package model;

import java.util.List;
import org.bson.types.ObjectId;
import com.google.code.morphia.dao.BasicDAO;
import com.google.code.morphia.query.Query;
import entity.Author;

public class AuthorModel extends BasicDAO<Author, ObjectId> {	
	private int pageSize = 40;

	public AuthorModel() {
		super(DBConnection.getMongo(), DBConnection.getMorphia(), DBConnection
				.getDatabase());
//		ds.ensureIndexes();
	}

	public List<Author> all(int currentPage) {
		Query<Author> q = ds.createQuery(Author.class);
		return q.limit(pageSize).offset(currentPage * pageSize).asList();
	}

	public Author findByAlias(String alias) {
		Query<Author> q = ds.createQuery(Author.class);
		q.field("alias").equal(alias);
		return q.get();
	}
}
